package top.go2do.auth.business.role.module;

import jakarta.persistence.*;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * @Description
 * @Author xingyj
 * @CreateTime 2025/5/15 15:01
 */
@Entity
@Table(name = "role", uniqueConstraints = {
        @UniqueConstraint(name = "idx_unique_app_role_code", columnNames ={"app_id", "role_code"}),
        @UniqueConstraint(name = "idx_unique_app_role_name", columnNames ={"app_id", "role_name"})
})
@Data
public class RolePO {
    @Id
    @Column(name = "role_id", columnDefinition = "BIGINT UNSIGNED COMMENT '角色ID(雪花算法分布式ID)'")
    private Long roleId;

    @Column(name = "app_id", nullable = false, columnDefinition = "VARCHAR(32) COMMENT '所属应用ID'")
    private String appId;

    @Column(name = "role_code", nullable = false, columnDefinition = "VARCHAR(100) COMMENT '角色编码（每个应用内唯一）'")
    private String roleCode;

    @Column(name = "role_name", nullable = false, columnDefinition = "VARCHAR(100) COMMENT '角色名称（每个应用内唯一）'")
    private String roleName;

    @Column(name = "is_default", nullable = false, insertable = false, columnDefinition = "BOOLEAN DEFAULT FALSE COMMENT '是否默认角色'")
    private Boolean isDefault;

    @Column(name = "created_at", nullable = false, insertable = false, updatable = false,
            columnDefinition = "DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间'")
    private LocalDateTime createdAt;

    @Column(name = "created_by", nullable = false,
            columnDefinition = "BIGINT UNSIGNED COMMENT '创建者'")
    private Long createdBy;

    @Column(name = "updated_at", nullable = false, insertable = false, updatable = false,
            columnDefinition = "DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间'")
    private LocalDateTime updatedAt;

    @Column(name = "updated_by", nullable = false,
            columnDefinition = "BIGINT UNSIGNED COMMENT '更新者'")
    private Long updatedBy;
}
